package com.gitee.wsl.doc.prosemirror.model.dom.parser

import com.fleeksoft.ksoup.nodes.Node as DOMNode
import com.gitee.wsl.doc.prosemirror.model.content.ContentMatch
import com.gitee.wsl.doc.prosemirror.model.content.ResolvedPos
import com.gitee.wsl.doc.prosemirror.model.dom.PreserveWhitespace
import com.gitee.wsl.doc.prosemirror.model.dom.parser.rule.ParseOptionsRule
import com.gitee.wsl.doc.prosemirror.model.node.Node


// These are the options recognized by the
// [`parse`](#model.DOMParser.parse) and
// [`parseSlice`](#model.DOMParser.parseSlice) methods.
interface ParseOptions {
    // By default, whitespace is collapsed as per HTML's rules. Pass
    // `true` to preserve whitespace, but normalize newlines to
    // spaces, and `"full"` to preserve whitespace entirely.
    val preserveWhitespace: PreserveWhitespace?

    // When given, the parser will, beside parsing the content,
    // record the document positions of the given DOM positions. It
    // will do so by writing to the objects, adding a `pos` property
    // that holds the document position. DOM positions that are not
    // in the parsed content will not be written to.
    val findPositions: List<ParseOptionPosition>?

    // The child node index to start parsing from.
    val from: Int?

    // The child node index to stop parsing at.
    val to: Int?

    // By default, the content is parsed into the schema's default
    // [top node type](#model.Schema.topNodeType). You can pass this
    // option to use the type and attributes from a different node
    // as the top container.
    val topNode: Node?

    // Provide the starting content match that content parsed into the
    // top node is matched against.
    val topMatch: ContentMatch?

    // A set of additional nodes to count as
    // [context](#model.ParseRule.context) when parsing, above the
    // given [top node](#model.ParseOptions.topNode).
    val context: ResolvedPos?

    val ruleFromNode: ((node: DOMNode) -> ParseOptionsRule?)?

    val topOpen: Boolean?
}

data class ParseOptionsImpl(
    override val preserveWhitespace: PreserveWhitespace? = null,
    override val findPositions: List<ParseOptionPosition>? = null,
    override val from: Int? = null,
    override val to: Int? = null,
    override val topNode: Node? = null,
    override val topMatch: ContentMatch? = null,
    override val context: ResolvedPos? = null,
    override val ruleFromNode: ((node: DOMNode) -> ParseOptionsRule?)? = null,
    override val topOpen: Boolean? = null
) : ParseOptions